package com.jd.user.dto;

import com.jd.basic.util.MD5Utils;
import com.jd.basic.util.StrUtils;
import com.jd.user.domain.User;
import lombok.Builder;
import lombok.Data;

import javax.validation.constraints.NotBlank;
import java.util.Date;

@Data
@Builder
public class EmailRegisterDto {
    @NotBlank(message = "邮箱不能为空")
    private String email;
    // uuid
    private String imageCodeKey;
    @NotBlank(message = "请输入图形验证码")
    // 图形验证码
    private String imageCodeValue;
    // 密码
    private String password;
    // 确认密码
    private String confirmPassword;
    // 短信验证码
    private String emailCode;
    public User getUser(){
        //盐值
        String salt = StrUtils.getComplexRandomString(32);
        String pw = MD5Utils.encrypByMd5(salt + this.password);
        return User
                .builder()
                .createtime(new Date())
                .salt(salt)
                .password(pw)
                .state(1)
                .email(this.email)
                .username(this.email)
                .build();
    }
}
